 /**
 * 逻辑、功能相关描述:
 *
 * @author yandawei 编写日期：2008-10-9
 */
package com.ce.pms.common.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.common.dao.IDataRightDao;
import com.ce.pms.common.model.SecUser;
import com.ce.pms.common.model.SecUserRelationRight;

/**
 * @author yandawei
 *
 */
public class DataRightDao extends PmsBaseDaoImpl<SecUserRelationRight> implements IDataRightDao {

	/* (non-Javadoc)
	 * @see com.ce.pms.common.dao.IDataRightDao#getUserDataRight(java.lang.Long)
	 */
	public Set<SecUserRelationRight> getUserDataRight(Long userId) {
		SecUser user = (SecUser) super.createQuery("from SecUser user where user.userId = ?", new Long[]{userId}).uniqueResult();
		Set<SecUserRelationRight> set = user.getSecUserRelationRights();
		return set;
	}

	public List<SecUserRelationRight> getBuildingRight(Long userId) {
		SecUser user = (SecUser) super.createQuery("from SecUser user where user.userId = ?", new Long[]{userId}).uniqueResult();
		List<SecUserRelationRight> list = new ArrayList<SecUserRelationRight>();

		for(SecUserRelationRight right : user.getSecUserRelationRights())
		{
			if("002".equals(right.getTypeCode()))
				list.add(right);
		}
		return list;
	}

	public List<SecUserRelationRight> getPrecinctRight(Long userId) {
		SecUser user = (SecUser) super.createQuery("from SecUser user where user.userId = ?", new Long[]{userId}).uniqueResult();
		List<SecUserRelationRight> list = new ArrayList<SecUserRelationRight>();

		for(SecUserRelationRight right : user.getSecUserRelationRights())
		{
			if("001".equals(right.getTypeCode()))
				list.add(right);
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.ce.pms.common.dao.IDataRightDao#executeHql(java.lang.String)
	 */
	public void executeHql(String hql) {
		Query query = createQuery(hql, null);
		query.executeUpdate();
	}

	/* (non-Javadoc)
	 * @see com.ce.pms.common.dao.IDataRightDao#getDataRightByUserId(java.lang.Long, java.lang.Long)
	 */
	public List<?> getDataRightByUserId(Long userId, Long hoursId) {
		Query query = createSQLQuery("SELECT * FROM V_GET_BUILDING_NAME_BY_USERID AS VDATE WHERE VDATE.HOUSE_ID = ? AND VDATE.USER_ID = ?", hoursId,userId);
		return query.list();
	}

}
